using UnityEngine;

public class BotTimerMedium : BotHoleController
{
	private bool runAway;

	private bool isOverAgressive;

	private new void Awake()
	{
		isOverAgressive = (Random.value < 0.3f);
	}

	private void Update()
	{
		if (!BaseGameManager.Instance.HasGameStarted || BaseGameManager.Instance._hasGameEnded)
		{
			return;
		}
		if (_hole.IsDead)
		{
			GoToFurthestTarget();
			return;
		}
		if ((bool)targetObject && targetObject.IsDestroyed)
		{
			target = null;
		}
		if ((bool)target)
		{
			if (DestroyTargetIfOutOfBounds())
			{
				return;
			}
			Vector3 vector = Vector3.MoveTowards(_cachedTransform.position, target.position, Time.deltaTime * _hole.Speed * _sensitivity);
			Vector3 position = _cachedTransform.position;
			vector.y = position.y;
			SetDirection(vector - _cachedTransform.position);
			_cachedTransform.position = vector;
			if (changeTargetTimer - Time.time < 0f)
			{
				target = null;
				if (runAway)
				{
					runAway = false;
				}
			}
			if (AreHoleAround() && !runAway)
			{
				target = FindFurthestTarget();
				if (target != null)
				{
					targetObject = target.GetComponent<FallingObjectBehaviour>();
					changeTargetTimer = Time.time + Random.Range(2f, 5f);
					runAway = true;
				}
			}
			return;
		}
		if (isOverAgressive)
		{
			target = FindClosestTarget();
		}
		else
		{
			float value = Random.value;
			if (value < 0.5f)
			{
				target = FindClosestTarget();
			}
			else
			{
				target = FindFurthestTarget();
			}
		}
		if (target != null)
		{
			targetObject = target.GetComponent<FallingObjectBehaviour>();
			changeTargetTimer = Time.time + Random.Range(5f, 10f);
		}
	}
}
